@extends('layout.personalInfo')

@section('title','地址管理')

@section('personalInfoContent')
<style type="text/css">
	table tr{
		border-collapse: collapse;
		border:solid 1px #ddd;

	}
	td{
		color:#222;
		font-size:14px;
	}
</style>
	<div class="col-md-8" style="margin-top:30px;margin-left:50px">
		<a href="/home/address/add">添加地址</a>
		<table class="table table-hover">
		  <tr>
			<td>收货人</td>
			<td>所在地区</td>		
			<td>详细地址</td>
			<td>联系方式</td>
			<td>操作</td>
			<td></td>
		  </tr>
		  @foreach($addr as $k=>$v)
		  <tr id="{{$v->id}}">
			<td>{{$v->consignee}}</td>
			<td>
				{{getAreaNameById($v->prov).'省' .getAreaNameById($v->city) .getAreaNameById($v->county)}}
			</td>
			<td>{{$v->detail}}</td>
			<td>{{$v->phone}}</td>
			<td>
				<a href="/home/address/edit?address_id={{$v->id}}">修改</a>
				<span> | </span>
				<a class="delete" addrid="{{$v->id}}" href="/home/address/delete?address_id={{$v->id}}">删除</a>
			</td>
			<td>
				@if($v->isdefault == 1)
					<span>默认地址</span>
				@endif
			</td>
		  </tr>
		  @endforeach
	</table>
	</div>
	<script type="text/javascript">
	$(function(){
		$('.delete').click(function(){
			var id = $(this).attr('addrid');
			$.get('/home/address/delete?address_id='+id,{},function(data){
				if(data == 1){
					$('#'+id).remove();
					alert('删除成功');
				}else{
					alert('删除失败');
				}
			})
			return false;
		})
	});
	</script>
@endsection